//
//  KEAlphabet-onClick.swift
//  KoalaEn
//
//  Created by Wade on 2024/9/10.
//

import Foundation
import UIKit
// https://dict.youdao.com/dictvoice?audio=I%20have%20an%20apple&type=2
extension KEClassifyListDetailVC{
    // 游戏按钮
    @objc func trainingBtnClick(){
        self.pushToGameView()
    }
    // 语言按钮
    @objc func aBtnClick(){
        KEAudioManager.sharedInstance.playEn(en: self.currentWords?.word_en ?? "", zh: "" )
    }
    // 图片点击
    @objc func wordsImageClick(){
        KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: "")
    }
    // 单词点击
    @objc func wordsBtnClick(){
        if mLanBtn?.isSelected == true {
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: "")
        }else{
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_en!)!,zh: (self.currentWords?.word_zh!)!)
        }
    }
    
    @objc func sentensBtnClick(){
        if mLanBtn?.isSelected == true {
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_sentences?.first!.word_sentences_en)!,zh: "")
        }else{
            KEAudioManager.sharedInstance.playEn(en: (self.currentWords?.word_sentences?.first!.word_sentences_en)!,zh: (self.currentWords?.word_sentences?.first!.word_sentences_zh)!)
        }
    }
    
    @objc func preViewBtnClick(){
        if self.currentIndex == 0 {
            // 提示
            print("已经到第一页了")
        }else{
            self.nextBtn?.isHidden = false
            self.currentIndex -= 1;
            
            springView2?.alpha = 1
            springView2?.duration = 0.75
            springView2?.rotate = 2.0
            springView2?.animation = "fadeInLeft"
            springView2?.animateToNext {
                self.setupWordWithIndex(self.currentIndex)
                self.springView?.isHidden = true
                self.springView2?.isHidden = false
                self.springView2?.alpha = 1
                self.springView2?.duration = 0.75
                self.springView2?.rotate = 2.0
                self.springView2?.animation = "fadeInRight"
                self.springView2?.animateNext(completion: {
                })
            }
            
        }
    }
    @objc func nextBtnClick(){
        if self.currentIndex >= self.wordList!.count - 1 {
            // 提示
            print("已经到最后一页了")
        }else{
            self.nextBtn?.isHidden = false
            self.preBtn?.isHidden = false
            self.currentIndex += 1;
            if(springView?.isHidden == false){
                springView?.alpha = 1
                springView?.duration = 0.75
                springView?.rotate = 2.0
                springView?.animation = "fadeInRight"
                springView?.animateToNext {
                    self.setupWordWithIndex(self.currentIndex)
                    self.springView?.isHidden = true
                    self.springView2?.isHidden = false
                    self.springView2?.alpha = 1
                    self.springView2?.duration = 0.75
                    self.springView2?.rotate = 2.0
                    self.springView2?.animation = "fadeInLeft"
                    self.springView2?.animateNext(completion: {
                    })
                }
            }else{
                springView2?.alpha = 1
                springView2?.duration = 0.75
                springView2?.rotate = 2.0
                springView2?.animation = "fadeInRight"
                springView2?.animateToNext {
                    self.setupWordWithIndex(self.currentIndex)
                    self.springView?.isHidden = true
                    self.springView2?.isHidden = false
                    self.springView2?.alpha = 1
                    self.springView2?.duration = 0.75
                    self.springView2?.rotate = 2.0
                    self.springView2?.animation = "fadeInLeft"
                    self.springView2?.animateNext(completion: {
                    })
                }
            }
        }
        
    }
    
    @objc func lanBtnClick(sender:UIButton){
        sender.isSelected = !sender.isSelected
        self.setupWordWithIndex(self.currentIndex)
    }
    @objc func recordBtnClick(){
        
    }
    @objc func startGameBtnClick(){
        
    }
    
}
